package com.zmn.oms.dubbo.impl.normal.reply;

import com.alibaba.fastjson.JSON;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.reflect.BeanMapper;
import com.zmn.oms.common.constant.OrderConsts;
import com.zmn.oms.common.dio.normal.reply.ReplyVisitDIO;
import com.zmn.oms.dubbo.interfaces.normal.reply.ReplyVisitModifyRemoteService;
import com.zmn.oms.dubbo.utils.DubboConsts;
import com.zmn.oms.model.dto.work.modify.must.ZsReplyVisitDTO;
import com.zmn.oms.model.vo.work.OperatePermissionVO;
import com.zmn.oms.zmn.business.interfaces.work.ZsOrderWorkOperatePermissionBService;
import com.zmn.oms.zmn.normal.business.interfaces.work.customwork.ZsNormalCustomWorkBService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 类描述：回访
 *
 * @author ligang
 * @since 2022/06/06 15:25
 */
@Slf4j
@DubboService(loadbalance = "roundrobin", timeout = 10000, retries = 0, version = DubboConsts.INTERFACE_VERSION, validation = "true")
public class ReplyVisitModifyRemoteServiceImpl implements ReplyVisitModifyRemoteService {

    @Autowired
    private ZsOrderWorkOperatePermissionBService orderWorkOperatePermissionBService;
    @Autowired
    private ZsNormalCustomWorkBService zsNormalCustomWorkBService;

    @Override
    public ResponseDTO saveReplyVisit(ReplyVisitDIO replyVisitDIO) {
        log.info("保存回访入参：【{}】", JSON.toJSONString(replyVisitDIO));
        try {
            OperatePermissionVO operatePermission = orderWorkOperatePermissionBService.getOperatePermission(replyVisitDIO.getOrderId(), replyVisitDIO.getWorkId(), OrderConsts.ORDER_OP_TYPE_REPLY_VISIT);
            if (!operatePermission.getCanOperate()) {
                return ResponseDTO.fail(operatePermission.getMsg());
            }
            ZsReplyVisitDTO zsReplyVisitDTO = JSON.parseObject(JSON.toJSONString(replyVisitDIO), ZsReplyVisitDTO.class);
            zsNormalCustomWorkBService.saveReplyVisit(zsReplyVisitDTO);
            return ResponseDTO.success();
        } catch (Exception e) {
            e.printStackTrace();
            log.error("保存回访失败", e);
            return ResponseDTO.fail("回访内容查询失败，请稍后重试");
        }
    }
}
